//tslint:disable
import { Component, OnInit, AfterViewInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';

import { ModalController, NavParams, IonSlides } from '@ionic/angular';

import { AppGlobalService } from '../../shared/service/app-global.service';

@Component({
    templateUrl: 'img.page.html',
    styleUrls: ['./slides-imgage.component.scss']
})
export class ImgSlidePage implements OnInit, AfterViewInit {
    data: any;
    index: any = 1;
    title: any;
    slideOpts: any;

    @ViewChild('slider') slider: IonSlides;

    constructor(private navParams: NavParams,
        private modalCtrl: ModalController,
        public router: Router,
        private appGlobalService: AppGlobalService) {
    }

    ngOnInit() {//  const value = {img: images, index, download};
        
        this.data = JSON.parse(this.navParams.data.value);
        // this.data.download = "true"; //debug
        this.title = this.navParams.data.title;
        this.slideOpts = { initialSlide: this.data.index - 1 };
        // this.slider.slideTo(this.data.index-1);
    }
    download(i,event){

        const path = this.data.img[i-1];
        this.appGlobalService.saveImageFromUrl(path, ((new Date()).valueOf() + path.substring(path.lastIndexOf(".") + 1, path.length)));
        event.stopPropagation();
        
    }
    ngAfterViewInit() {
    }

    getprevIndex() {
        this.index -= 1;
    }

    getnextIndex() {
        this.index += 1;
    }

    dismiss() {
        this.modalCtrl.dismiss();
    }

    delete(i) {
        this.data.splice(i, 1);
    }

}
